<template>
    <a-card :bordered="false">
        <a-form ref="searchFormRef" name="advanced_search" :model="searchFormState" class="ant-advanced-search-form mb-4">
            <a-row :gutter="24">
                <a-col :span="6">
                    <a-form-item label="学年学期" name="xnxq01id">
                        <a-input v-model:value="searchFormState.xnxq01id" placeholder="请输入学年学期" />
                    </a-form-item>
                </a-col>
                <a-col :span="6">
                    <a-form-item label="上课班级名称" name="skbjmc">
                        <a-input v-model:value="searchFormState.skbjmc" placeholder="请输入上课班级名称" />
                    </a-form-item>
                </a-col>
                <a-col :span="6">
                    <a-form-item label="课程名称" name="kcmc">
                        <a-input v-model:value="searchFormState.kcmc" placeholder="请输入课程名称" />
                    </a-form-item>
                </a-col>
                <template v-if="advanced">
                    <a-col :span="6">
                        <a-form-item label="合班名称" name="hbmc">
                            <a-input v-model:value="searchFormState.hbmc" placeholder="请输入合班名称" />
                        </a-form-item>
                    </a-col>
                </template>
                <template v-if="advanced">
                    <a-col :span="6">
                        <a-form-item label="上课教师工号" name="skjsjgh">
                            <a-input v-model:value="searchFormState.skjsjgh" placeholder="请输入上课教师工号" />
                        </a-form-item>
                    </a-col>
                </template>
                <template v-if="advanced">
                    <a-col :span="6">
                        <a-form-item label="上课教师名称" name="skjsmc">
                            <a-input v-model:value="searchFormState.skjsmc" placeholder="请输入上课教师名称" />
                        </a-form-item>
                    </a-col>
                </template>
                <template v-if="advanced">
                    <a-col :span="6">
                        <a-form-item label="上课时间" name="sksj">
                            <a-input v-model:value="searchFormState.sksj" placeholder="请输入上课时间" />
                        </a-form-item>
                    </a-col>
                </template>
                <template v-if="advanced">
                    <a-col :span="6">
                        <a-form-item label="上课地点" name="skdd">
                            <a-input v-model:value="searchFormState.skdd" placeholder="请输入上课地点" />
                        </a-form-item>
                    </a-col>
                </template>
                <a-col :span="6">
                    <a-button type="primary" @click="table.refresh(true)">查询</a-button>
                    <a-button style="margin: 0 8px" @click="() => searchFormRef.resetFields()">重置</a-button>
					<a @click="toggleAdvanced" style="margin-left: 8px">
						{{ advanced ? '收起' : '展开' }}
						<component :is="advanced ? 'up-outlined' : 'down-outlined'"/>
					</a>
				</a-col>
				<template v-if="advanced">
				<a-col :span="6">
					<a-button style="margin: 0 8px" @click="exportJxrwInfo(record)">导出全部课表</a-button>
					<a-button style="margin: 0 8px" @click="exportJxrwListInfo(record)">导出课程清单</a-button>
				</a-col>
				<a-col :span="6">
					<a-button style="margin: 0 8px" @click="exportJxrwInfo4Tea(record)">导出教师课表</a-button>
					<a-button style="margin: 0 8px" @click="exportJxrwInfo4Room(record)">导出教室课表</a-button>

                </a-col>
				</template>
            </a-row>
        </a-form>
        <s-table
            ref="table"
            :columns="columns"
            :data="loadData"
            :alert="options.alert.show"
            bordered
            :row-key="(record) => record.kkdm"
            :tool-config="toolConfig"
            :row-selection="options.rowSelection"
        >
<!--            <template #operator class="table-operator">
           <a-space>
                <a-button type="primary" @click="formRef.onOpen()" v-if="hasPerm('jwJxrwAdd')">
                    <template #icon><plus-outlined /></template>
                    新增
                </a-button>
                <xn-batch-button
                    v-if="hasPerm('jwJxrwBatchDelete')"
                    buttonName="批量删除"
                       icon="DeleteOutlined"
                    :selectedRowKeys="selectedRowKeys"
                    @batchCallBack="deleteBatchJwJxrw"
                />
            </a-space>
            </template>-->
<!--            <template #bodyCell="{ column, record }">
                <template v-if="column.dataIndex === 'action'">
                    <a-space>
                        <a @click="formRef.onOpen(record)" v-if="hasPerm('jwJxrwEdit')">编辑</a>
                        <a-divider type="vertical" v-if="hasPerm(['jwJxrwEdit', 'jwJxrwDelete'], 'and')" />
                        <a-popconfirm title="确定要删除吗？" @confirm="deleteJwJxrw(record)">
                            <a-button type="link" danger size="small" v-if="hasPerm('jwJxrwDelete')">删除</a-button>
                        </a-popconfirm>
                    </a-space>
                </template>
            </template>-->
        </s-table>
    </a-card>
    <Form ref="formRef" @successful="table.refresh(true)" />
</template>

<script setup name="jxrw">
    import { message } from 'ant-design-vue'
    import Form from './form.vue'
    import jwJxrwApi from '@/api/biz/jwJxrwApi'
	import userApi from "@/api/sys/userApi";
	import downloadUtil from "@/utils/downloadUtil"
/*计算当前学年学期*/
	const now = new Date() // 创建当前时间的Date对象
	const year = now.getFullYear() // 获取年份
	const month = now.getMonth() + 1
	const xnxq=month>8?year+'-'+(year+1)+'-1':(year-1)+'-'+year+'-2'

    let searchFormState = reactive({sksj:'星',xnxq01id:xnxq})
    const searchFormRef = ref()
    const table = ref()
    const formRef = ref()
    const toolConfig = { refresh: true, height: true, columnSetting: true, striped: false }
    // 查询区域显示更多控制
    const advanced = ref(false)
    const toggleAdvanced = () => {
        advanced.value = !advanced.value
    }
    const columns = [
        {
            title: '学年学期',
            dataIndex: 'xnxq01id'
        },

        {
            title: '上课班级名称',
            dataIndex: 'skbjmc'
        },
		{
			title: '合班名称',
			dataIndex: 'hbmc'
		},
        {
            title: '课程名称',
            dataIndex: 'kcmc'
        },
        {
            title: '教工号',
            dataIndex: 'skjsjgh'
        },
        {
            title: '教师名',
            dataIndex: 'skjsmc'
        },
        {
            title: '周次',
            dataIndex: 'skzc'
        },
        {
            title: '上课时间',
            dataIndex: 'sksj'
        },
        {
            title: '上课地点',
            dataIndex: 'skdd'
        },

        {
            title: '周学时',
            dataIndex: 'zzxs'
        },
		{
			title: '总学时',
			dataIndex: 'zxs'
		},

		{
            title: '理论学时',
            dataIndex: 'llxs'
        },
        {
            title: '实验学时',
            dataIndex: 'syxs'
        },
        {
            title: '实践学时',
            dataIndex: 'sjxs'
        },
        {
            title: '其它学时',
            dataIndex: 'qtxs'
        },

    ]
    // 操作栏通过权限判断是否显示
    // if (hasPerm(['jwJxrwEdit', 'jwJxrwDelete'])) {
    //     columns.push({
    //         title: '操作',
    //         dataIndex: 'action',
    //         align: 'center',
    //         width: '150px'
    //     })
    // }
    let selectedRowKeys = ref([])
    // 列表选择配置
    const options = {
        alert: {
            show: false,
            clear: () => {
                selectedRowKeys = ref([])
            }
        },
        rowSelection: {
            onChange: (selectedRowKey, selectedRows) => {
                selectedRowKeys.value = selectedRowKey
            }
        }
    }
    const loadData = (parameter) => {
        const searchFormParam = JSON.parse(JSON.stringify(searchFormState))
        return jwJxrwApi.jwJxrwPage(Object.assign(parameter, searchFormParam)).then((data) => {
            return data
        })
    }
	// 导出课表信息
	const exportJxrwInfo = () => {
		const searchFormParam = JSON.parse(JSON.stringify(searchFormState))
		jwJxrwApi.jwExportJxrwInfo(searchFormParam).then((res) => {
			downloadUtil.resultDownload(res)
		})
	}
	// 导出课程清单信息
	const exportJxrwListInfo = () => {
		const searchFormParam = JSON.parse(JSON.stringify(searchFormState))
		jwJxrwApi.jwExportJxrwListInfo(searchFormParam).then((res) => {
			downloadUtil.resultDownload(res)
		})
	}
	// 导出教师课表信息
	const exportJxrwInfo4Tea = () => {
		const searchFormParam = JSON.parse(JSON.stringify(searchFormState))
		jwJxrwApi.jwExportJxrw4Tea(searchFormParam).then((res) => {
			downloadUtil.resultDownload(res)
		})
	}
	// 导出教室课表信息
	const exportJxrwInfo4Room = () => {
		const searchFormParam = JSON.parse(JSON.stringify(searchFormState))
		jwJxrwApi.jwExportJxrw4Room(searchFormParam).then((res) => {
			downloadUtil.resultDownload(res)
		})
	}
    // 删除
    const deleteJwJxrw = (record) => {
        let params = [
            {
                kkdm: record.kkdm
            }
        ]
        jwJxrwApi.jwJxrwDelete(params).then(() => {
            table.value.refresh(true)
        })
    }
    // 批量删除
    const deleteBatchJwJxrw = () => {
        if (selectedRowKeys.value.length < 1) {
            message.warning('请选择一条或多条数据')
            return false
        }
        const params = selectedRowKeys.value.map((m) => {
            return {
                kkdm: m
            }
        })
        jwJxrwApi.jwJxrwDelete(params).then(() => {
            table.value.clearRefreshSelected()
        })
    }
</script>
